package com.jjmmbb.baoSudoku;

import android.content.Intent;
import android.content.pm.PackageManager.NameNotFoundException;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.TextView;

import com.adb.dao.GameDataManager;
import com.adb.util.Util;

/**
 * 打开本页面前需要初始化comm.currentAVData和comm.currentGameData
 * 
 * @author yizhe
 * @date 2012-7-13
 */
public class HelpActivity extends BaseActivity implements OnClickListener {
	TextView versionView, vRateView, vQQ, vWeixin;
	CheckBox cb_wakelock;

	long ad_js = 0; // 单击广告时的计时,用于模拟双击

	int payType = 1; // 1:解锁本关,2:解锁全部

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.help);
		versionView = (TextView) findViewById(R.id.help_tv_version);
		vRateView = (TextView) findViewById(R.id.help_rate);
		vQQ = (TextView) findViewById(R.id.help_qq);
		vWeixin = (TextView) findViewById(R.id.help_weixin);

		vRateView.setOnClickListener(this);
		vQQ.setOnClickListener(this);
		vWeixin.setOnClickListener(this);

		ini();
	}

	public void ini() {
		try {
			Comm.version = getPackageManager().getPackageInfo(
					this.getPackageName(), 0).versionName;
			versionView
					.setText(getStr(R.string.app_name) + " v" + Comm.version);
		} catch (NameNotFoundException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void onClick(View v) {
		Uri uri;
		Intent intent;
		switch (v.getId()) {
		case R.id.help_rate:
			uri = Uri.parse("market://details?id=com.jjmmbb.jxSudoku");
			intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
			break;
		case R.id.help_qq:
			copyToClip(getStr(R.string.app_qq));
			uri = Uri
					.parse("http://qm.qq.com/cgi-bin/qm/qr?k=Mk/8p7jnSnR10vGwZLDSpUx+t5hYFJx9");
			intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);
			break;
		case R.id.help_weixin:
			copyToClip(getStr(R.string.app_weixin));
			uri = Uri.parse("http://weixin.qq.com/r/OnU7I1bE9guJrRJA9yAo");
			intent = new Intent(Intent.ACTION_VIEW, uri);
			startActivity(intent);

			break;
		}
	}

	// 解锁女优
	void openAV() {
		if (1 == payType) {
			// 解开某一关
			Comm.currentGameData.setState(1);
			GameDataManager gdm = new GameDataManager();
			gdm.update(this, Comm.currentGameData);
			toast("已经成功解救,请刷新列表");
		} else {
			// 软件激活
			Comm.isBuy = true;
			Util.saveBuy2Preferences(this);
			toast(R.string.msg_ispuy);
		}
	}

	// --------------工具,方法-------------------------//
	private void copyToClip(String strText) {
		android.text.ClipboardManager clipboardManager = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
		clipboardManager.setText(strText);
		toast(R.string.msg_copySuccess);
	}
}
